using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace ChuyenDongVatLy
{
   
    public class ThanhMPN : Microsoft.Xna.Framework.GameComponent
    {
        private double _angle;
        private float _length;
        private Vector2 _position;
        public Vector2 Position
        {
            get { return _position; }
            set { _position = value; }
        }

        public float Length
        {
            get { return _length; }
            set { _length = value; }
        }
        private Game1 game;
        private Texture2D _image;       

        public Texture2D Image
        {
            get { return _image; }
            set { _image = value; }
        }
        public Rectangle GetRect()
        {
            return new Rectangle((int)_position.X,(int)_position.Y,(int)_length,ConstPhysic.heightMPN);
        }
        public double Angle
        {
            get { return _angle; }
            set { _angle = value; }
        }
        public ThanhMPN(Game1 game,double gocnghieng,float chieudai,Vector2 vitri)
            : base(game)
        {
            this.game = game;
            this._angle = gocnghieng;
            this._length = chieudai;
            this._position = vitri;

        }
        public override void Initialize()
        {          
            base.Initialize();
        }
        public void LoadContent(ContentManager Content)
        {
            _image = Content.Load<Texture2D>("gach");
        }
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }
        public void Draw(SpriteBatch sp)
        {
            sp.Draw(_image, _position, new Rectangle(0, 0, (int)_length, ConstPhysic.heightMPN), Color.White, (float)_angle * -1, new Vector2(0, 0), 1.0f, SpriteEffects.None, 0);
        }
        public Line LineOfMPN()
        {
            Geometry ge = new Geometry();
            Vector2 d1 = _position;
            Vector2 d2 = new Vector2((float)(_position.X+_length*Math.Cos(_angle)),(float)(_position.Y-_length*Math.Sin(_angle)));
            Line l1 = ge.DuongThangQua2Diem(d1, d2);
            return l1;
        }
        public Vector2 PointEnd()
        {
            return new Vector2((float)(_position.X + _length * Math.Cos(_angle)), (float)(_position.Y - _length * Math.Sin(_angle)));
        }
    }
}
